package com.lordjoe.collectiveintelligence.pricemodel;

import com.lordjoe.collectiveintelligence.data.*;

import java.util.*;

/**
 * com.lordjoe.collectiveintelligence.pricemodel.WineModel
 *
 * @author Steve Lewis
 * @date May 12, 2009
 */
public class WineModel extends DataItem
{
    public static WineModel[] EMPTY_ARRAY = {};
    public static Class THIS_CLASS = WineModel.class;

    public static final double MINIMUM_PRICE = 2.99;

    public static final Random RND = new Random();

    public static final IMeasurementType<Integer> WineAge =
            new MeasurementType("Age",Integer.class);
    public static final IMeasurementType<Integer> WineRating =
            new MeasurementType("Rating",Integer.class);
    public static final IMeasurementType<Double> WinePrice =
            new MeasurementType("Price",Double.class);

    public static WineBottle generateBottle()
    {
        int rating = 50 + (int)(50 * RND.nextDouble());
        int age = (int)(50 * RND.nextDouble());
        WineBottle ret = new WineBottle(age,rating);
          // apply the model
         double modelPrice = (Double)WinePriceModel.INSTANCE.generateValue(ret);
        // add noise
         modelPrice = Math.max(MINIMUM_PRICE,DataUtilities.gaussian(modelPrice,0.3 * modelPrice));
         ret.setPrice(modelPrice);

        return ret;
    }

    public static WineBottle[] generateBottles(int number)
    {
        List<WineBottle> holder = new ArrayList<WineBottle>();
        while(holder.size() < number) {
            holder.add(generateBottle());
        }
        WineBottle[] ret = new WineBottle[holder.size()];
        holder.toArray(ret);
        return ret;
    }

    public static Dataset generateDataset()
    {
        WineBottle[] bottles = generateBottles(100);
        Dataset ds = new Dataset("Wine Price");
        for (int i = 0; i < bottles.length; i++) {
            WineBottle bottle = bottles[i];
            ds.addItem(bottle);
        }
        return ds;
    }

    public WineModel()
    {
    }

    public static void main(String[] args)
    {
        Dataset dataset = generateDataset();
    }

}
